package com.tanhua.server.controller;

import cn.hutool.core.convert.Convert;
import com.tanhua.server.service.MyCenterService;
import com.tanhua.server.vo.PageResult;
import com.tanhua.server.vo.SettingsVo;
import com.tanhua.server.vo.UserInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("users")
public class MyCenterController {

    @Autowired
    private MyCenterService myCenterService;

    /**
     * 查询我的 用户信息
     * @return
     */
    @GetMapping
    public UserInfoVo queryUserInfo(@RequestParam(value = "userID", required = false) Long userId) {
        // return this.myCenterService.queryUserInfoVo();
        return this.myCenterService.queryUserInfoByUserId(userId);
    }

    /**
     * 更新头像
     * @param headPhoto
     * @return
     */
    @PostMapping("header")
    public Object updateHeadPhoto(@RequestBody MultipartFile headPhoto){
        return this.myCenterService.updateHeadPhoto(headPhoto);
    }

    /**
     * 更新头像
     * @param userInfoVo
     * @return
     */
    @PutMapping
    public Object updateUserInfo(@RequestBody UserInfoVo userInfoVo){
        return this.myCenterService.updateUserInfo(userInfoVo);
    }

    /**
     * 设置陌生人问题
     * @param param
     * @return
     */
    @PostMapping("questions")
    public Object saveQuestion(@RequestBody Map<String, Object> param) {
        String content = Convert.toStr(param.get("content"));
        return this.myCenterService.saveQuestion(content);
    }

    /**
     * 用户通用设置 - 读取
     * @return
     */
    @GetMapping("settings")
    public SettingsVo queryCommonSettings() {
        return this.myCenterService.queryCommonSettings();
    }

    /**
     * 通知设置 - 保存
     * @return
     */
    @PostMapping("notifications/setting")
    public Object updateSettings(@RequestBody Map<String, Object> param) {
        Boolean likeNotification = Convert.toBool(param.get("likeNotification"));
        Boolean pinglunNotification = Convert.toBool(param.get("pinglunNotification"));
        Boolean gonggaoNotification = Convert.toBool(param.get("gonggaoNotification"));
        return this.myCenterService.updateSettings(likeNotification, pinglunNotification, gonggaoNotification);
    }

    /**
     * 获取黑名单列表
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("blacklist")
    public PageResult queryBlackList(@RequestParam(value = "page", defaultValue = "1") String page,
                                     @RequestParam(value = "pageSize", defaultValue = "10") String pageSize) {
        return this.myCenterService.queryBlackList(page, pageSize);
    }

    /**
     * 删除黑名单
     * @param blackUserId
     * @return
     */
    @DeleteMapping("/blacklist/{uid}")
    public Object deleteBlackUser(@PathVariable("uid") String blackUserId) {
        return this.myCenterService.deleteBlackUser(blackUserId);
    }

}
